import appium.webdriver


"""
   获取driver 
"""
class GetDriver:
    __app_driver = None

    # 获取driver
    @classmethod
    def get_app_driver(cls):
        # 获取app driver
        if cls.__app_driver is None:
            # 设置启动
            desired_caps = {}
            # 必填-且正确
            desired_caps["platformName"] = "Android"
            # 必填-且正确
            desired_caps["platformVersion"] = "13"  # 9、10、13
            # 必填
            desired_caps["deviceName"] = "RFCR71NPQBT"
            # APP包名  com.xtty.biubiubiu/com.fs.xdm.ui.activity.SplashActivity
            ## com.android.settings /.Settings
            desired_caps["appPackage"] = "com.xtty.biubiubiu.browser"
            # 启动名
            desired_caps["appActivity"] = "com.fs.xdm.ui.activity.SplashActivity"
            # 设置中文
            desired_caps["unicodeKeyboard"] = True
            desired_caps["resetKeyboard"] = True
            # 配置 UiAutomator2 解决找不到元素的问题
            desired_caps["automationName"] = "uiautomator2"
            # desired_caps["ANDROID_UIAUTOMATOR"] = "uiautomator2"
            desired_caps["ignoreHiddenApiPolicyError"] = True
            # 不每次重置app
            desired_caps["noReset"] = True
            # 防止通信超时,20分钟
            desired_caps["newCommandTimeout"] = 1200
            # 设置driver
            cls.__app_driver = appium.webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
        return cls.__app_driver









